<template>
	<view class="uni-fab-box">
		
		<view v-if="!projectLists || projectLists.length === 0" class="uni-flex uni-row" 
			style="-webkit-justify-content: center;justify-content: center;">
			<view class="none-tip-text">暂无数据</view>
		</view>
		
		<view v-else>
			<uni-card v-for="(item,index) in projectLists" :title="item.projectName" isShadow @click="handleProjectClick(item)">
				<view><text class="content-box-text">{{item.projectDesc}}</text></view>
			</uni-card>
		</view>
	</view>
</template>

<script>
	import { getProjectInfo } from '@/api/projectInfo.js'
	export default {
		data() {
			return {
				projectQuery: {
					page: 1,
					size: 10,
					param: { }
				},
				projectLists: [],
				projectTotal: 0,
				isLoading: false
			}
		},
		onReachBottom(){
			if(this.isLoading || this.projectLists.length >= this.projectTotal) {
				return;
			}
			this.isLoading = true;
			this.projectQuery.page = this.projectQuery.page + 1;
			this.getProjectLists();
		},
		onPullDownRefresh() {
			this.projectQuery.page = 1;
			this.projectLists = [];
			this.getProjectLists();
		},
		onShow() {
			this.projectQuery.page = 1;
			this.projectLists = [];
			this.getProjectLists();
		},
		methods: {
			getProjectLists() {
				getProjectInfo(this.projectQuery)
				.then(resp => {
					resp.datas.datas.forEach(x => this.projectLists.push(x))
					this.projectTotal = resp.datas.total;
					this.isLoading = false;
					uni.stopPullDownRefresh();
				})
				.catch(error => {
					uni.stopPullDownRefresh();
					uni.showToast({
						title: error,
						icon: 'none',
						duration: 1000
					})
				});
			},
			handleProjectClick(item) {
				uni.navigateTo({
					url: "/pages/projectItemInfo/project_item_lists?id=" + encodeURIComponent(item.id)
				})
			}
		}
	}
</script>
